package com.qf.service.impl;

import com.qf.po.UserInfo;
import com.qf.repository.UserInfoRepository;
import com.qf.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoRepository userInfoRepository;
    @Override
    public List<UserInfo> finds() {
        List<UserInfo> all = userInfoRepository.findAll();
        return all;
    }

    @Override
    public UserInfo find(Integer id) {
        Optional<UserInfo> byId = userInfoRepository.findById(id);
        UserInfo userInfo = byId.get();
        return userInfo;
    }

    @Override
    public UserInfo add(UserInfo userInfo) {
        UserInfo save = userInfoRepository.save(userInfo);
        return save;
    }

    @Override
    public UserInfo update(UserInfo userInfo) {
        UserInfo userInfo1 = userInfoRepository.saveAndFlush(userInfo);
        return userInfo1;
    }

    @Override
    public boolean delete(Integer id) {
        try {
            userInfoRepository.deleteById(id);
            return true;
        }catch (Exception e){
            return false;
        }

    }
}
